<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" th:with="title='商品管理',active='goods'">
<head th:replace="/manage/header::headerFragment(title,active)"></head>
<body>
<div th:replace="/manage/header::header-body"></div>
<div class="row">
  <div class="col-2">
    <div th:replace="/manage/leftnav::leftnav"></div>
  </div>
  <div class="col-10 content-page">
    <div class="row" style="padding: 20px 0 0 40px">
        <a th:href="@{/manage/goods/addGoods}" class="btn btn-primary col-2">
          新增商品
        </a>
      <div class="col-lg-6">
        <form action="find_goods" method="get">
          <div class="input-group">
            <input type="text" class="form-control" name="find_goods" id="find_goods" placeholder="搜索商品...">
            <span class="input-group-btn">
               <button class="btn btn-default" type="submit">搜索!</button>
            </span>
          </div><!-- /input-group -->

        </form>

      </div><!-- /.col-lg-6 -->
    </div>

    <form id="edit_user_form" enctype="multipart/form-data" method="post">
      <!-- 修改分类模态框 -->
      <div class="modal" id="updateModal">
        <div class="modal-dialog">
          <div class="modal-content">

            <!-- 模态框头部 -->
            <div class="modal-header">
              <h4 class="modal-title">修改用户信息</h4>
              <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
            </div>

            <!-- 模态框内容 -->
            <div class="modal-body">
              <input type="hidden" class="form-control" id="user_id" name="user_id">
              <div class="mb-3 mt-3">
                <label for="user_name" class="form-label">用户名</label>
                <input type="text" class="form-control" id="user_name" placeholder="用户名" name="user_name">
              </div>
              <div class="mb-3 mt-3">
                <label for="user_pass" class="form-label">密码</label>
                <input type="text" class="form-control" id="user_pass" placeholder="密码" name="user_pass">
              </div>
              <div class="mb-3 mt-3">
                <label for="user_age" class="form-label">年龄</label>
                <input type="text" class="form-control" id="user_age" placeholder="年龄" name="user_age">
              </div>
              <!--              <div class="mb-3 mt-3">-->
              <!--                <label for="user_name" class="form-label">性别</label>-->
              <!--                <input type="text" class="form-control" id="user_sex" placeholder="性别" name="user_sex">-->
              <!--              </div>-->
              <div class="mb-3 mt-3">-->
                <label for="user_sex" class="col-sm-2 control-label">性别</label>
                <div class="col-sm-10" id="user_sex">
                  <input type="radio" name="user_sex" id="radio1" value="1" > 男
                  <input type="radio" name="user_sex" id="radio2" value="0" >女
                </div>
              </div>

              <div class="mb-3 mt-3">
                <label for="user_email" class="form-label">邮箱</label>
                <input type="text" class="form-control" id="user_email" placeholder="邮箱" name="user_email">
              </div>
              <!--              <div class="mb-3 mt-3">-->
              <!--                <label for="user_rank" class="form-label">用户身份</label>-->
              <!--                <input type="text" class="form-control" id="user_rank" placeholder="用户身份" name="user_rank">-->
              <!--              </div>-->
              <div class="mb-3 mt-3">-->
                <label for="user_rank" class="col-sm-2 control-label">身份</label>
                <div class="col-sm-10" id="user_rank">
                  <input type="radio" name="user_rank" id="radio3" value="1" > 管理员
                  <input type="radio" name="user_rank" id="radio4" value="0" >用户
                </div>
              </div>
            </div>
            <!-- 模态框底部 -->
            <div class="modal-footer">
              <button type="button" class="btn btn-success" onclick="updateUser108()">提交</button>
              <button type="button" class="btn btn-danger" data-bs-dismiss="modal">关闭</button>
            </div>

          </div>
        </div>
      </div>
    </form>

    <form id="add_form" class="was-validated" enctype="multipart/form-data" method="post">
      <!-- 新增分类模态框 -->
      <div class="modal" id="addModal">
        <div class="modal-dialog">
          <div class="modal-content">

            <!-- 模态框头部 -->
            <div class="modal-header">
              <h4 class="modal-title">新增商品</h4>
              <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
            </div>

            <!-- 模态框内容 -->
            <div class="modal-body">
              <div class="form-group">
                <label for="new_user_name" class="col-sm-2 control-label">
                  用户名称
                </label>
                <div class="col-sm-10">
                  <input type="text" class="form-control" id="new_user_name" placeholder="请输入用户名" name="user_name"/>
                </div>
              </div>
              <div class="form-group">
                <label for="new_user_pass" class="col-sm-2 control-label">用户密码</label>
                <div class="col-sm-10">
                  <input type="text" class="form-control" id="new_user_pass" placeholder="请输入密码" name="user_pass"/>
                </div>
              </div>
              <div class="form-group">
                <label for="new_user_age" class="col-sm-2 control-label">年龄</label>
                <div class="col-sm-10">
                  <input type="text" class="form-control" id="new_user_age" placeholder="请输入年龄" name="user_age"/>
                </div>
              </div>
              <div class="form-group">
                <label for="new_user_sex" class="col-sm-2 control-label">性别</label>
                <div class="col-sm-10" id="new_user_sex">
                  <input type="radio" name="user_sex" id="optionsRadios1" value="1" checked> 男
                  <input type="radio" name="user_sex" id="optionsRadios2" value="0" >女
                </div>
              </div>
              <div class="form-group">
                <label for="new_user_email" class="col-sm-2 control-label">邮箱</label>
                <div class="col-sm-10">
                  <input type="text" class="form-control" id="new_user_email" placeholder="请输入年龄" name="user_email" />
                </div>
              </div>
            </div>
            <!-- 模态框底部 -->
            <div class="modal-footer">
              <button type="button" class="btn btn-success" onclick="addUser108()">提交</button>
              <button type="button" class="btn btn-danger" data-bs-dismiss="modal">关闭</button>
            </div>

          </div>
        </div>
      </div>
    </form>

    <script th:inline="javascript">
      // 通过id获取修改的商品信息
      function getUserInfo108(id,name,pass,age,sex,email,rank) {
        $("#user_id").val(id);
        $("#user_name").val(name);
        $("#user_pass").val(pass);
        $("#user_age").val(age);
        $("#user_sex").val(sex);
        $("#user_email").val(email);
        $("#user_rank").val(rank);
      }

      // 修改商品分类
      function updateUser108() {
        $.ajax({
          url: "updateUser108",
          type: "POST",//方法类型
          cache: false,
          processData: false,
          contentType: false,
          dataType: "json",
          data: new FormData($('#edit_user_form')[0]),
          success: function (data) {
            // alert(data);
            if (data.result == "success") {
              alert(data.msg);
              window.location.reload();
            } else {
              alert(data.msg);
            }
          }, error: function (xhr, status, error) {
            alert("请求失败!" + status);
          }
        });
      }

      /*新增商品分类
      * 使用formData数据格式提交form表单数据，该格式主要针对input=file，上传文件时使用。
      * 如何ajax提交数据未formData格式，必须定义以下两个参数值。 processData: false 表示不使用applicati/x-www-form-urlencode。
      * contentType: false 表示不采用默认的数据类型
      */
      function addUser108() {
        $.ajax({
          url:"addUser108",
          type: "POST",//方法类型
          cache : false,
          processData: false,
          contentType: false,
          dataType:"json",
          data: new FormData($('#add_form')[0]),
          success: function(data){
            // alert(data);
            if(data.result=="success"){
              alert(data.msg);
              window.location.reload();
            }else{
              alert(data.msg);
            }
          },error:function(xhr,status,error){
            alert("请求失败!"+status);
          }
        });
      }

    </script>

    <!--//面板-->
    <div class="row" style="padding-left: 20px">
      <table class="table table-striped">
        <thead>
        <tr>
          <th><input type="checkbox" id="selAllGoods" onchange="selGoodsBut('goodsForm', 'goodsIds')"> 全选</th>
          <th>#</th>
          <th>商品名称</th>
          <th>商品图片</th>
          <th>商品价格</th>
          <th>商品折后价格</th>
          <th>商品库存</th>
          <th>商品材质</th>
          <th>商品运费</th>
          <th>商品销量</th>
          <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <tr th:each="good : ${goods.list}">
          <td><input type="checkbox" name="goodsIds" th:value="${good.goods_id}" ></td>
          <td th:text="${good.goods_id}">1</td>
          <td th:text="${good.goods_name}"></td>
          <td><img th:src="@{${good.goods_pic}}" width="50" height="50"></td>
          <td th:text="${good.goods_price}"></td>
          <td th:text="${good.goods_discount}">439.0</td>
          <td th:text="${good.goods_stock}">h90</td>
          <td th:text="${good.goods_material}">毛呢</td>
          <td th:text="${good.goods_postalfee}">10</td>
          <td th:text="${good.goods_sales}">52</td>
          <td><a th:href="@{${#servletContext.contextPath+'goods/handleGoods'}(goodsId=${good.goods_id})}">修改</a>
            | <a th:href="@{${#servletContext.contextPath+'goods/delGoods'}(goodsId=${good.goods_id})}" onclick="return confirm('确定要删除这个商品吗？')">删除</a></td>
        </tr>
        </tbody>
      </table>

    </div>

    <!-- 文章分页信息 -->
    <div class="row">
      <div th:replace="common/paging :: pageAdminNav(${goods})"></div>
    </div>

  </div>

</div>


<div th:replace="/manage/footer::footer"></div>
</body>
</html>